import Vuex from 'vuex';
import Vue from 'vue';

Vue.use(Vuex);

const state = {
    counter: 1,
};
const mutations = {
    increase: function(state) {
        state.counter += 1;
    },
    decrease: function(state) {
        state.counter -= 1;
    },
};
const actions = {
    increase: function({ commit, state }) {
        commit('increase');
    },
    decrease: function({ commit, state }) {
        commit('decrease');
    },
    async: function(store) {
        new Promise(function() {
            setTimeout(function() {
                store.commit('increase')
            }, 2000)
        })
    }
};
const getters = {
    oddOreven: function(state) {
        return state.counter % 2 == 0 ? 'even' : 'odd'
    }
}

export default new Vuex.Store({
    state,
    mutations,
    actions,
    getters
})